<template>
  <div class="app-container">

    

    <!-- 添加或修改立项通知（市监）对话框 -->

      <el-card class="box-card" v-if="steps == '2' || steps == '3'">
        <div slot="header" class="clearfix">
          <span style="font-size: 16px;font-weight: 600;">项目基础信息</span>
        </div>
        <el-form ref="form" :model="form" :rules="rules" label-width="120px">
          <el-col :span="12">
            <el-form-item label="项目名称" prop="projectName">
              <el-input v-model="form.projectName" placeholder="项目名称" required maxlength="50"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="项目关键词" prop="keyword">
              <el-input v-model="form.keyword" placeholder="项目关键词，多个关键词用，隔开" maxlength="50" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="专业门类选择" prop="majorValue">
              <el-cascader style="width: 380px;" v-model='majorValue' :options="majorOptions" @change="handleChangeMajor"></el-cascader>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="功能序列选择" prop="functionValue">
              <el-cascader style="width: 380px;" v-model='functionValue' :options="functionOptions" @change="handleChangeFunction"></el-cascader>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="标准性质" prop="standardNature">
              <el-select style="width: 380px;" v-model="form.standardNature" placeholder="请选择">
                <el-option v-for="dict in typeStandardNatureOptions" :key="dict.dictValue" :label="dict.dictLabel"
                  :value="dict.dictValue" />
              </el-select>
            </el-form-item>
          </el-col>

        </el-form>
      </el-card>

      <el-card class="box-card" style="margin-top: 20px;" v-if="steps == '2'">
        <div slot="header" class="clearfix">
          <span style="font-size: 16px;font-weight: 600;">市场监管局标准规范立项信息</span>
        </div>
        <el-form ref="form" :model="form" :rules="rules" label-width="120px">
          <el-row>
            <el-col :span="12">
              <el-form-item label="制定或修订" prop="tp">
                <el-radio-group v-model="form.tp" size="small">
                  <el-radio-button label="制定"></el-radio-button>
                  <el-radio-button label="修订"></el-radio-button>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="被修订标准号" v-if="form.tp == '修订'"  prop="standardNo">
                <el-input v-model="form.standardNo" placeholder="被修订标准号开" maxlength="50" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="项目承担单位" prop="hostUnit">
                <el-input v-model="form.hostUnit" placeholder="项目承担单位" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="计划完成时间" prop="pctm">
                <el-date-picker v-model="form.pctm" type="date" placeholder="选择日期">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="项目负责人" prop="pi">
                <el-input v-model="form.pi" placeholder="项目负责人"  maxlength="50"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="职务" prop="post">
                <el-input v-model="form.post" placeholder="职务"  maxlength="50"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="电话" prop="tel">
                <el-input v-model="form.tel" placeholder="电话"  maxlength="50"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="电子邮件" prop="email">
                <el-input v-model="form.email" placeholder="电子邮件"  maxlength="50"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="参与起草单位" prop="partUnit">
                <el-input v-model="form.partUnit" placeholder="参与起草单位名称"  maxlength="250"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="失效时间" prop="expire">
                <el-date-picker v-model="form.expire" type="date" placeholder="选择日期">
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>

          <el-col :span="24">
            <h4>>>>主要起草人（前五位，按在起草工作中的贡献度排名）
            <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAddDrafter" round v-if="!viewOpt&&!optPage">
            添加</el-button>
            </h4>
          </el-col>
          <el-table :data="tableData" style="width: 100%" border>
            <el-table-column prop="dname" label="姓名" width="180">
            </el-table-column>
            <el-table-column prop="dcompany" label="工作单位" width="180">
            </el-table-column>
            <el-table-column prop="dpost" label="职务职称">
            </el-table-column>
            <el-table-column prop="dspeciality" label="专业">
            </el-table-column>
            <el-table-column prop="dproject" label="项目分工">
            </el-table-column>
            <el-table-column label="操作" align="left" class-name="small-padding fixed-width" v-if="!viewOpt&&!optPage">
              <template slot-scope="scope">
                <el-button size="mini" type="text" icon="el-icon-edit"
                  @click="handleUpdateDrafter(scope.row)" >编辑
                </el-button>
                <el-button size="mini" type="text" icon="el-icon-delete"
                  @click="handleDeleteDrafter(scope.row)" >删除
                </el-button>
              </template>
            </el-table-column>
          </el-table>
          <el-col :span="24">
            <h4>>>>目的、意义及必要性</h4>
          </el-col>
          <el-row>
            <el-col :span="24">
              <el-form-item label-width="0px;">
                <el-input v-model="form.goalDesc" type="textarea" placeholder="请输入内容"></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-col :span="24">
            <h4>>>>国内外情况简要说明</h4>
          </el-col>
          <el-row>
            <el-col :span="24">
              <el-form-item label-width="0px;">
                <el-input v-model="form.infosDesc" type="textarea" placeholder="请输入内容"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-col :span="24">
            <h4>>>>范围和主要技术内容</h4>
          </el-col>
          <el-row>
            <el-col :span="24">
              <el-form-item label-width="0px;">
                <el-input v-model="form.techDesc" type="textarea" placeholder="请输入内容"></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-col :span="24">
            <h4>>>>可行性分析</h4>
          </el-col>
          <el-row>
            <el-col :span="24">
              <el-form-item label-width="0px;">
                <el-input v-model="form.analysisDesc" type="textarea" placeholder="请输入内容"></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-col :span="24">
            <h4>>>>是否涉及专利等知识产权问题</h4>
          </el-col>
          <el-row>
            <el-col :span="24">
              <el-form-item label-width="0px;">
                <el-input v-model="form.propertyDesc" type="textarea" placeholder="请输入内容"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-card>


      <el-card class="box-card" style="margin-top: 20px;" v-if="steps == '3'">

        <div slot="header" class="clearfix">
          <span style="font-size: 16px;font-weight: 600;">市住建局标准规范立项信息</span>
        </div>
        <el-form ref="form" :model="form" :rules="rules" label-width="120px">
          <el-row>
            <el-col :span="12">
              <el-form-item label="项目英文名称" prop="enName">
                <el-input v-model="form.enName" placeholder="项目英文名称"  maxlength="50"/>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="制定或修订" prop="tp">
                <el-radio-group v-model="form.tp" size="small">
                  <el-radio-button label="制定"></el-radio-button>
                  <el-radio-button label="修订"></el-radio-button>
                </el-radio-group>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="被修订标准号" v-if="form.tp == '修订'" prop="standardNo">
                <el-input v-model="form.standardNo" placeholder="被修订标准号"  maxlength="50"/>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="项目主编单位" prop="hostUnit">
                <el-input v-model="form.hostUnit" placeholder="项目主编(申报)单位"  maxlength="50"/>
              </el-form-item>
            </el-col>

            <el-col :span="24">
              <el-form-item label="主编单位资格条件情况说明" prop="hostUnitDesc">
                <el-input v-model="form.hostUnitDesc" type="textarea" rows="3" placeholder="（含主编或参编的本市在编工程建设标准制修订项目计划进度完成情况，若有）"></el-input>
              </el-form-item>
            </el-col>

            <el-col :span="24">
              <el-form-item label="参编单位" prop="partUnit">
                <el-input v-model="form.partUnit" placeholder="参编单位"  maxlength="250"/>
              </el-form-item>
            </el-col>

            <el-col :span="24" v-if="form.tp == '修订'">
              <el-form-item label="申报单位是" prop="isHostUnit">
                <el-tooltip class="item" effect="dark" content="修订项目填写" placement="right">
                  <el-radio-group v-model="form.isHostUnit">
                    <el-radio v-for="dict in stdDeclareUnitOptions" :key="dict.dictValue" :label="dict.dictValue">{{dict.dictLabel}}</el-radio>
                  </el-radio-group>
                </el-tooltip>
              </el-form-item>
            </el-col>

            <el-col :span="24" v-if="form.isHostUnit == '1' || form.isHostUnit == '2'">
              <el-form-item label="原主编单位意见" prop="exOpinion">
                <el-input v-model="form.exOpinion" type="textarea" placeholder="(若非原主编单位)"></el-input>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="计划完成时间" prop="pctm">
                <el-date-picker v-model="form.pctm" type="date" placeholder="选择日期">
                </el-date-picker>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="项目负责人" prop="pi">
                <el-input v-model="form.pi" placeholder="项目负责人"  maxlength="50"/>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="职务" prop="post">
                <el-input v-model="form.post" placeholder="职务"  maxlength="50"/>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="电话" prop="tel">
                <el-input v-model="form.tel" placeholder="电话"  maxlength="50"/>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="失效时间" prop="expire">
                <el-date-picker v-model="form.expire" type="date" placeholder="选择日期">
                </el-date-picker>
              </el-form-item>
            </el-col>

          </el-row>

          <el-col :span="24">
            <h4>>>>有无国家、本省本市法律法规、规范、政策和重点工作部署相关依据的情况说明</h4>
          </el-col>
          <el-row>
            <el-col :span="24">
              <el-form-item label-width="0px;">
                <el-input v-model="form.lawDesc" type="textarea" placeholder="请输入内容"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-col :span="24">
            <h4>>>>目的、意义及必要性</h4>
          </el-col>

          <el-row>
            <el-col :span="24">
              <el-form-item label-width="0px;">
                <el-input v-model="form.goalDesc" type="textarea" placeholder="请输入内容"></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-col :span="24">
            <h4>>>>有无相关国家标准、行业标准、地方标准情况说明</h4>
          </el-col>
          <el-row>
            <el-col :span="24">
              <el-form-item label-width="0px;">
                <el-input v-model="form.stdDesc" type="textarea" placeholder="请输入内容"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-col :span="24">
            <h4>>>>有无团体标准、本企业编制的企业标准或本市政府发布的技术性指导文件的情况说明</h4>
          </el-col>
          <el-row>
            <el-col :span="24">
              <el-form-item label-width="0px;">
                <el-input v-model="form.techDesc" type="textarea" placeholder="请输入内容"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-col :span="24">
            <h4>>>>与国内相关标准对标情况的综合说明（含港澳台地区，可将香港等粤港澳大湾区及国内相关重点城市或地区作为对标重点）</h4>
          </el-col>
          <el-row>
            <el-col :span="24">
              <el-form-item label-width="0px;">
                <el-input v-model="form.countryDesc" type="textarea" placeholder="请输入内容"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-col :span="24">
            <h4>>>>与国际相关标准对标情况的综合说明（可将欧洲、英国、日本、新加坡等国家和地区作为对标重点，但不限于上述国家和地区）</h4>
          </el-col>
          <el-row>
            <el-col :span="24">
              <el-form-item label-width="0px;">
                <el-input v-model="form.foreignDesc" type="textarea" placeholder="请输入内容"></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-col :span="24">
            <h4>>>>对标或借鉴的国际、国外或区域性（含港澳台地区和国内重点城市）先进标准名称、编号清单</h4>
          </el-col>
          <el-row>
            <el-col :span="24">
              <el-form-item label-width="0px;">
                <el-input v-model="form.foreignStdList" type="textarea" placeholder="请输入内容"></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-col :span="24">
            <h4>>>>涵盖范围和主要内容说明</h4>
          </el-col>
          <el-row>
            <el-col :span="24">
              <el-form-item label-width="0px;">
                <el-input v-model="form.infosDesc" type="textarea" placeholder="请输入内容"></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-col :span="24">
            <h4>>>>涉及的科研成果鉴定、验证或认可情况说明</h4>
          </el-col>
          <el-row>
            <el-col :span="24">
              <el-form-item label-width="0px;">
                <el-input v-model="form.achievementDesc" type="textarea" placeholder="请输入内容"></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-col :span="24">
            <h4>>>>是否涉及专利相关事项说明</h4>
          </el-col>
          <el-row>
            <el-col :span="24">
              <el-form-item label-width="0px;">
                <el-input v-model="form.propertyDesc" type="textarea" placeholder="请输入内容"></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-col :span="24">
            <h4>>>>先进性、创新性和因地制宜等情况说明</h4>
          </el-col>
          <el-row>
            <el-col :span="24">
              <el-form-item label-width="0px;">
                <el-input v-model="form.advanceDesc" type="textarea" placeholder="请输入内容"></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="24">
              <el-form-item label="自评价(可多选)" prop="selfEvla">
                <el-checkbox-group v-model="selfEvlaOpt" @change="handleCheckedSelfEvla">
                  <el-checkbox label="填补本市空白">填补本市空白</el-checkbox>
                  <el-checkbox label="填补国内空白">填补国内空白（不含港澳台地区）</el-checkbox>
                  <el-checkbox label="可达到国内领先水平">可达到国内领先水平</el-checkbox>
                  <el-checkbox label="可达到国际先进水平">可达到国际先进水平</el-checkbox>
                </el-checkbox-group>
              </el-form-item>
            </el-col>
          </el-row>

          <el-col :span="24">
            <h4>>>>工作经费安排情况说明</h4>
          </el-col>
          <el-row>
            <el-col :span="24">
              <el-form-item label-width="0px;">
                <el-input v-model="form.fundsDesc" type="textarea" placeholder="请输入内容"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-card>

      <el-card class="box-card" style="margin-top: 20px;" v-if="(steps == '2' || steps == '3')">
        <div slot="header" class="clearfix">
          <span style="font-size: 16px;font-weight: 600;">附件信息</span>
          <SPAN class="text-info" >（只能上传word/pdf文件，且不超过20M）</SPAN>
        </div>
        <el-form label-width="120px">
          <el-row>
            <el-col :span="12">
              <el-form-item label="标准规范立项表" prop="files">
                <el-upload
                  ref="upload"
                  accept=".pdf,.doc,.docx"
                  :headers="upload.headers"
                  action="#"
                  :disabled="fileEditDisabled"
                  :on-change="handleCheckFile"
                  :on-preview="handleViewFile"
                  :on-remove="handleRemoveFile"
                  :http-request="requestUpload"
                  :before-upload="beforeUpload"
                  :before-remove="beforeRemoveFile"
                  :auto-upload="false"
                  :file-list="fileList"
                   >
                  <el-button size="small" icon="el-icon-upload2" :disabled="fileEditDisabled">点击上传</el-button>
                  <!-- <div class="el-upload__tip" slot="tip" >提示：只能上传word/pdf/png/jpg文件，且不超过20M！</div> -->
                </el-upload>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-card>

      <el-card class="box-card" style="margin-top: 20px;" v-if="optPage||viewOpt">
        <div slot="header" class="clearfix">
          <span style="font-size: 16px;font-weight: 600;">部门办理意见</span>
        </div>
        <el-form label-width="120px">
          <el-row v-for="opn in opinionList" :key="opn.id">
            <el-col :span="24">
              <el-form-item :label="opn.node">
                <el-input placeholder="" type="textarea" :value="opn.opn" readonly></el-input>
                <div style="position: absolute;right:20px;margin-top: -30px;">
                  <span>{{opn.name}}</span>
                  <span style="margin-left: 20px;">{{opn.st}}</span>
                </div>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-card>

      <div slot="footer" class="dialog-footer" v-if="(steps == '2' || steps == '3') && !viewOpt ">
        <!-- 开始办理 -->
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submitForm" v-if="!optPage || form.wStatus=='0'" >保 存</el-button>
        <el-button type="primary" @click="handleOpinion" >开始办理</el-button>
        <!-- <el-button @click="back" v-if=" lastStep && !optPage " >上一步</el-button> -->
        <!-- 先保存，再由经办人开启流程
        <el-button type="primary" @click="handleFlowTo" v-if="!optPage">提交部门审核</el-button>
        -->
      </div>

      <!-- 开始办理对话框 -->
      <el-dialog title="开始办理" :visible.sync="openOpt" width="650px" append-to-body>

        <el-form ref="formOpt" :model="formOpt" label-width="100px">
          <el-row>
            <el-col :span="16">
              <el-form-item label="办理人意见">
                <el-input v-model="myOpinion" type="textarea" rows="5" placeholder=""></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8" class="word_hui">
              <el-button size="small" style="margin-top: 3px;margin-left: 10px;" @click="inputOpinion">同意。</el-button>
              <el-button size="small" style="margin-top: 3px;" @click="inputOpinion">已阅。</el-button>
              <el-button size="small" style="margin-top: 3px;" @click="inputOpinion">退回。</el-button>
              <el-button size="small" style="margin-top: 3px;" @click="inputOpinion">抓紧办理。</el-button>
              <el-button size="small" style="margin-top: 3px;" @click="inputOpinion">重新修改。</el-button>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="流程提交至">

                <el-tooltip placement="right-end">
                  <div slot="content">
                  选择流程结束时，将自动提交至“标准规范起草”环节~
                  </div>
                  <el-select v-model="submitTo" value-key="dictValue" placeholder="请选择" @change="handleCheckedFlowTo">
                    <el-option v-for="dict in flowToOptions" :key="dict.dictValue" :label="dict.dictLabel" :value="dict.dictValue" />
                  </el-select>
                </el-tooltip>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row v-if="flowToLabel!='流程结束'">
            <el-col :span="24">
              <el-form-item :label="flowToLabel">
                <el-select v-model="submitToName" value-key="userId" placeholder="请选择">
                  <!-- @change="handleCheckedFlowToName" 暂时没用上 -->
                  <el-option v-for="user in flowToNameOptions" :key="user.userId" :label="user.nickName" :value="user.userId" />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>

        <div slot="footer" class="dialog-footer">
          <el-button @click="openOpt = false">返 回</el-button>
          <el-button type="primary" @click="submitOptForm">办理完成</el-button>
        </div>
      </el-dialog>

      <!-- 添加起草人对话框 -->
      <el-dialog title="起草人信息" :visible.sync="openDraft" width="650px" append-to-body>
        <el-form ref="formDraft" :model="formDraft" :rules="drules" label-width="100px">
          <el-row>
            <el-col :span="12">
              <el-form-item label="姓名" prop="dname" maxlength="20" required>
                <el-input v-model="formDraft.dname" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="工作单位" prop="dcompany" maxlength="50" required>
                <el-input v-model="formDraft.dcompany" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="职务职称" prop="dpost" maxlength="50" required>
                <el-input v-model="formDraft.dpost" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="专业" prop="dspeciality" maxlength="50" required>
                <el-input v-model="formDraft.dspeciality" />
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="项目分工" prop="dproject" maxlength="250" required>
                <el-input v-model="formDraft.dproject" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>

        <div slot="footer" class="dialog-footer">
          <el-button @click="openDraft = false">返 回</el-button>
          <el-button type="primary" @click="submitDraftForm">确 定</el-button>
        </div>
      </el-dialog>


  </div>
</template>

<script>
  import {
    listNotice,
    getNotice,
    delNotice,
    addNotice,
    updateNotice,
    exportNotice,

    // testList,
    //==================================== private start ====================================
    updateUploadFile,
    delUploadFile,
    getUploadFiles
    //==================================== private end ====================================
  } from '@/api/standard/notice'

  import { exportM } from "@/api/standard/m";

  import {
    optionSelect
  } from "@/api/system/dict/data";
  import {
    flowSelect
  } from "@/api/system/role";
  import store from "@/store";
  import {
    getFlow,
    selectOptions,
    saveFlow,
    listOpinion
  } from "@/api/standard/flow";
  // 默认流程
  import flowToDefault from "@/utils/flowToDefault";

  import { delDrafter, addDrafter, updateDrafter } from "@/api/standard/drafter";

  import {
    getToken
  } from "@/utils/auth";

  export default {
    name: 'M',
    data() {
      return {
        // 遮罩层
        loading: false,
        // 表单id
        id: '',
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 弹出层标题
        title: '',
        // 是否显示弹出层
        open: false,
        openView: false,

        // 是否为来自首页的访问
        askFromIndex: false,

        // 立项通知（市监）表格数据
        mList: [],
        tableData: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          params: null,
          prjName: null,
          processStatus: null,
          operatorName: null,
          currOptName: null,
          standardType: null,
          auditCompany: null,
          editCompany: null,
        },
        // 日期范围
        dateRange: [],

        work: {
          todo: 8,
          done: 24,
          doing: 17,
          back: 3,
        },
        //当前步骤0,1,2,3
        steps: 0,

        //专业门类选择
        majorValue: [],
        majorOptions: [],
        //功能序列选择
        functionValue: [],
        functionOptions: [],
        // 自我评价
        selfEvlaOpt: [],
        // 类型数据字典
        typeOptions: [],
        typeStandardNatureOptions: [],
        typeStandardStatusOptions: [],
        typeStandardLevelOptions: [],
        typeStandardUnitOptions: [],
        // 申报单位
        stdDeclareUnitOptions: [],
        standardNature: null,
        standardStatus: null,
        //标准类型
        standardType: null,
        //单位
        unitType: null,
        //是否修改页面
        lastStep: true,
        openOpt: false,

        //起草人信息
        openDraft: false,
        formDraft: {},

        // 是否查看页面
        viewOpt: false,
        // 是否办理页面
        optPage: false,
        // 角色选项
        roleOptions: [],
        // 流程节点
        flowToOptions: [],
        flowToNameOptions: [],
        // 当前用户名
        userName: store.getters && store.getters.name,
        roles: store.getters && store.getters.roles,
        submitToName: null,
        myOpinion: null,
        submitTo: null, //当前选择的流程节点
        flowToLabel: null, //
        opinionList: [],
        // 默认流程节点
        defaultFlowToList: flowToDefault,

        // ================ 附件参数 ================
        // 上传多附件时,只执行一次
        fileIndex: 0,
        // 用作页面展示的上传文件list
        fileList: [],
        // 用作上传到后台的file参数
        uploadfileList: [],
        // 记录附件是否发生变化
        fileChange: false,
        // 被删除的文件名称
        delFileName: null,
        // 新上传的附件数量
        countNewFile: 0,

        // 是否允许编辑附件
        fileEditDisabled: false,
        // 是否自动上传
        autoUpload: false,

        // 附件上传
        upload: {
          updateSupport: 0,
          // 设置上传的请求头部
          headers: {
            Authorization: "Bearer " + getToken()
          },
          // 上传的地址
          url: process.env.VUE_APP_BASE_API + "/standard/notice/attachment"
        },

        // 表单参数
        form: {},
        // 办理表单参数
        formOpt: {},
        // 表单校验
        rules: {
          userid: [{
            required: true,
            message: '用户id不能为空',
            trigger: 'blur'
          }],
          nextNodeK: [{
            required: true,
            message: '请选择流程提交至',
            trigger: 'blur'
          }],
          nextNode: [{
            required: true,
            message: '请选择办理人',
            trigger: 'blur'
          }],
        },
        drules: {
          dname: [{
            required: true,
            message: '姓名不能为空',
            trigger: 'blur'
          }],
          dcompany: [{
            required: true,
            message: '单位不能为空',
            trigger: 'blur'
          }],
          dpost: [{
            required: true,
            message: '姓名不能为空',
            trigger: 'blur'
          }],
          dproject: [{
            required: true,
            message: '项目分工不能为空',
            trigger: 'blur'
          }],
          dspeciality: [{
            required: true,
            message: '专业不能为空',
            trigger: 'blur'
          }],
        },
      }
    },
    created() {

      this.getList();

      this.id = this.$route.query.id;

      //立项通知流程状态
      this.getDicts('standard_notice_type').then(response => {
        this.typeOptions = response.data
        // 默认选中起草
      });
      //标准性质
      this.getDicts('standard_nature_type').then(response => {
        this.typeStandardNatureOptions = response.data
      });
      //标准状态
      this.getDicts('standard_status_type').then(response => {
        this.typeStandardStatusOptions = response.data
      });
      //专业门类选择
      optionSelect("standard_major_type").then(response => {
        this.majorOptions = this.cascaderNormalizer(response.data)
      });
      //功能序列选择
      optionSelect("standard_function_type").then(response => {
        this.functionOptions = this.cascaderNormalizer(response.data)
      });
      //标准规范立项单位
      this.getDicts("standard_project_unit").then(response => {
        this.typeStandardUnitOptions = response.data
      });
      //标准规范种类
      this.getDicts("standard_level_type").then(response => {
        this.typeStandardLevelOptions = response.data
      });
      //申报单位
      this.getDicts("standard_declare_unit").then(response => {
        this.stdDeclareUnitOptions = response.data
      });

      // this.handleTransact('2e4acb44109b4df4b32ac6af1efa1105');
      this.handleView('2e4acb44109b4df4b32ac6af1efa1105');

    },
    methods: {
      /** 查询立项通知（市监）列表 */
      getList() {
        this.loading = true
        listNotice(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          this.mList = response.rows
          this.total = response.total
          this.loading = false
          // 默认打开
          const nid = this.$route.query.nid;
          if(nid!=null&&!this.askFromIndex){//false的时候才执行，变成true这个方法就不执行了
            this.askFromIndex = true;
            this.openPageFromIndex();
          }
        })
      },

      // 从首页点击办理/查看，默认打开页面
      openPageFromIndex() {
        const nid = this.$route.query.nid;
        const operatType = this.$route.query.operatType;
        var row = null;
        // console.log(nid)
        if(nid!=null){
          // console.log(this.total)
          for(var i=0;i<this.total;i++){
            var row_nid = this.mList[i].nid;
            if(row_nid==nid){
              row = this.mList[i];
              break;
            }
          }

          if(operatType!=null&&operatType=='view'&&row!=null){
            this.handleView(row);
          }else if(operatType=='handle'&&row!=null){
            this.handleTransact(row)
          }
        }
      },

      // 获取用户信息
      getUser() {
        getUserProfile().then(response => {
          this.user = response.data;
        });
      },

      // 标准规范种类字典翻译
      stdTpFormat(row, column) {
        return this.selectDictLabel(this.typeStandardLevelOptions, row.stdTp);
      },

      // 审核单位字典翻译
      stdUnitFormat(row, column) {
        return this.selectDictLabel(this.typeStandardUnitOptions, row.stdUnit);
      },

      // 提交部门审核
      flowTo() {
        this.open = false
        this.steps = 0
        // this.lastStep = true
        this.reset()
        this.msgSuccess('提交成功')
      },

      // 取消按钮
      cancel() {
        this.open = false
        this.steps = 0
        // this.lastStep = true
        this.reset()
      },
      // 表单重置
      reset() {
        this.form = {
          nid: null,
          userid: null,
          wid: null,
          nname: null,
          eunit: null,
          pctm: null,
          expire: null,
          ld: null,
          partUnit: null,
          ldp: null,
          isHostUnit: null,
          ldu: null,
          projectName: null,
          keyword: null,
          majorValue: null,
          functionValue: null,
          standardNature: null,
          standardStatus: 1,
          enName: null,
          tp: null,
          standardNo: null,
          hostUnit: null,
          planTime: null,
          pi: null,
          post: null,
          tel: null,
          email: null,
          hostUnitOpinion: null,
          authUnitOpinion: null,
          mainUnitOpinion: null,
          stdTp: '地方标准',
          exOpinion: null,
          stdUnit: null,
          goalDesc: null,
          wStatus: "0",
          infosDesc: null,
          techDesc: null,
          analysisDesc: null,
          propertyDesc: null,
          hostUnitDesc: null,
          lawDesc: null,
          stdDesc: null,
          countryDesc: null,
          foreignDesc: null,
          foreignStdList: null,
          achievementDesc: null,
          advanceDesc: null,
          fundsDesc: null,
          selfEvla: null
        }
        this.resetForm('form')

        this.viewOpt = false

        // 重置的时候,数组都要注意置空
        this.majorValue = null
        this.functionValue = null
        this.selfEvlaOpt = null

        this.tableData = [];
      },

      resetOptForm() {
        this.formOpt = {
          id: null,
          nid: null,
          stamp: null,
          userid: null,
          opt: null,
          ctn: null,
          res: null,
          opn: null,
          flowToUserid: null,
          flowToRoleid: null,
          flowToDeptid: null,
          currNodeK: null,
          currNode: null,
          nextNodeK: null,
          nextNode: null
        };
        this.resetForm("formOpt");
      },

      // 根据选中的角色,查找相应的用户清单
      handleCheckedFlowTo(value) {
        this.submitToName = null
        this.flowToNameOptions = []

        if (value == 'end') {
          this.flowToLabel = "流程结束"
          return false
        }

        const userid = this.formOpt.userid
        selectOptions(userid, value).then(response => {
          this.flowToNameOptions = response.data
          // 默认选择第一个
          if (this.flowToNameOptions.length>0) {
            this.submitToName = this.flowToNameOptions[0].userId
          }
          if (value == 'operator') { // 经办人
            this.submitToName = this.form.userid
            this.formOpt.userid = this.submitToName
          }
        });

        let obj = this.flowToOptions.find((item) => { //这里的carslist就是上面遍历的数据源
          return item.dictValue === value; //筛选出匹配数据
        });
        // console.log(obj); //obj即是选中的Option数据集合
        //获取到选中的Option数据集并进行其它操作
        this.flowToLabel = obj.dictLabel
      },

      /** 选中人员 */
      handleCheckedFlowToName(value) {
        //console.log(value)
        this.formOpt.userid = value
      },

      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1
        this.getList()
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm('queryForm')
        this.handleQuery()
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.nid)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },

      /** 查看操作 */
      handleView(id) {
        //避免切换（住建/市监）时报错
        this.steps = 0

        this.reset()

        // 清空附件列表
        this.fileList = []
        this.uploadfileList = []
        // 记录附件是否发生变更
        this.fileChange = false
        // 文件游标
        this.fileIndex = 0
        // 新增附件数
        this.countNewFile = 0

        this.fileEditDisabled = true

        const nid = id || this.ids
        getNotice(nid).then(response => {
          this.functionValue = response.data.functionValue == null ? [] : response.data.functionValue.split(",").map(
            Number);
          this.majorValue = response.data.majorValue == null ? [] : response.data.majorValue.split(",").map(Number);
          this.selfEvlaOpt = response.data.selfEvla == null ? [] : response.data.selfEvla.split(",").map(String);
          if (response.data.stdUnit == '深圳市住房和建设局') {
            this.steps = 3
          } else {
            this.steps = 2
          }
          this.form = response.data

          this.optPage = false
          this.title = '查看立项通知'
          // 查看标记
          this.viewOpt = true

          this.tableData = response.data.drafters;

          //加载办理意见列表
          this.opinionInfos();
        })

        // 加载附件
        getUploadFiles(nid).then(response => {
          for(var i=0;i<response.data.length;i++){
            var img = {}
            img.name = response.data[i].fname
            img.url = process.env.VUE_APP_BASE_API + response.data[i].filename
            this.fileList.push(img)
          }
        });

        this.open = true

      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset()

        this.steps = 0
        this.askFromIndex = false;
        // this.lastStep = true
        this.selfEvlaOpt = []
        this.optPage = false
        this.viewOpt = false

        // 清空附件列表
        this.fileList = []
        this.uploadfileList = []
        // 记录附件是否发生变更
        this.fileChange = false
        // 文件游标
        this.fileIndex = 0
        // 新增附件数
        this.countNewFile = 0

        this.fileEditDisabled = false

        this.title = '新增立项通知'
        this.open = true
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        //避免切换（住建/市监）时报错
        this.steps = 0
        this.reset()

        // 清空附件列表
        this.fileList = []
        this.uploadfileList = []
        // 记录附件是否发生变更
        this.fileChange = false
        // 文件游标
        this.fileIndex = 0
        // 新增附件数
        this.countNewFile = 0

        this.fileEditDisabled = false

        const nid = row.nid || this.ids
        getNotice(nid).then(response => {
          this.functionValue = response.data.functionValue == null ? [] : response.data.functionValue.split(",").map(
            Number);
          this.majorValue = response.data.majorValue == null ? [] : response.data.majorValue.split(",").map(Number);
          this.selfEvlaOpt = response.data.selfEvla == null ? [] : response.data.selfEvla.split(",").map(String);

          // this.lastStep = false
          if (response.data.stdUnit == '深圳市住房和建设局') {
            this.steps = 3
          } else {
            this.steps = 2
          }

          this.form = response.data
          // this.open = true
          this.optPage = false

          this.title = '修改立项通知'

          this.tableData = response.data.drafters;

          //但凡是修改，都要重新审核
          this.form.wStatus = "0"

          //加载办理意见列表
          // this.opinionInfos();

        });

        // 加载附件
        getUploadFiles(nid).then(response => {
          for(var i=0;i<response.data.length;i++){
            var img = {}
            img.name = response.data[i].fname
            img.url = process.env.VUE_APP_BASE_API + response.data[i].filename
            this.fileList.push(img)
          }
        });

        this.open = true

      },
      // 办理按钮操作
      handleTransact(id) {
        console.log(11111111111111111)
        console.log(id)
        console.log(22222222222222222)
        //避免切换（住建/市监）时报错
        this.steps = 0
        this.reset()

        // 清空附件列表
        this.fileList = []
        this.uploadfileList = []
        // 记录附件是否发生变更
        this.fileChange = false
        // 文件游标
        this.fileIndex = 0
        // 新增附件数
        this.countNewFile = 0

        const nid = id || this.ids
        getNotice(nid).then(response => {
          this.functionValue = response.data.functionValue == null ? [] : response.data.functionValue.split(",").map(
            Number);
          this.majorValue = response.data.majorValue == null ? [] : response.data.majorValue.split(",").map(Number);
          this.selfEvlaOpt = response.data.selfEvla == null ? [] : response.data.selfEvla.split(",").map(String);

          // this.lastStep = false
          if (response.data.stdUnit == '深圳市住房和建设局') {
            this.steps = 3
          } else {
            this.steps = 2
          }
          this.lastStep = false
          this.form = response.data
          // this.open = true
          //办理页面
          this.optPage = true
          this.title = '办理立项通知'

          if(this.form.wStatus=='0'){
            // 不允许编辑附件
            this.fileEditDisabled = false;
          }else{
            this.fileEditDisabled = true;
          }

          this.tableData = response.data.drafters;

          //准备办理页面数据
          this.pageOpinion();

          //加载办理意见列表
          this.opinionInfos();

        })

        // 加载附件
        getUploadFiles(nid).then(response => {
          for(var i=0;i<response.data.length;i++){
            var img = {}
            img.name = response.data[i].fname
            img.url = process.env.VUE_APP_BASE_API + response.data[i].filename
            this.fileList.push(img)
          }
        });

        this.open = true
      },
      // 办理按钮操作
      handleTransact12(row) {
        console.log(11111111111111111)
        console.log(row)
        console.log(22222222222222222)
        //避免切换（住建/市监）时报错
        this.steps = 0
        this.reset()

        // 清空附件列表
        this.fileList = []
        this.uploadfileList = []
        // 记录附件是否发生变更
        this.fileChange = false
        // 文件游标
        this.fileIndex = 0
        // 新增附件数
        this.countNewFile = 0

        const nid = row.nid || this.ids
        getNotice(nid).then(response => {
          this.functionValue = response.data.functionValue == null ? [] : response.data.functionValue.split(",").map(
            Number);
          this.majorValue = response.data.majorValue == null ? [] : response.data.majorValue.split(",").map(Number);
          this.selfEvlaOpt = response.data.selfEvla == null ? [] : response.data.selfEvla.split(",").map(String);

          // this.lastStep = false
          if (response.data.stdUnit == '深圳市住房和建设局') {
            this.steps = 3
          } else {
            this.steps = 2
          }
          this.lastStep = false
          this.form = response.data
          // this.open = true
          //办理页面
          this.optPage = true
          this.title = '办理立项通知'

          if(this.form.wStatus=='0'){
            // 不允许编辑附件
            this.fileEditDisabled = false;
          }else{
            this.fileEditDisabled = true;
          }

          this.tableData = response.data.drafters;

          //准备办理页面数据
          this.pageOpinion();

          //加载办理意见列表
          this.opinionInfos();

        })

        // 加载附件
        getUploadFiles(nid).then(response => {
          for(var i=0;i<response.data.length;i++){
            var img = {}
            img.name = response.data[i].fname
            img.url = process.env.VUE_APP_BASE_API + response.data[i].filename
            this.fileList.push(img)
          }
        });

        this.open = true
      },

      // 流程记录
      opinionInfos() {
        var tableName = 'tb_nop_m'
        listOpinion(this.form.nid, tableName).then(response => {
          // console.log(response.data)
          this.opinionList = response.data
        });
      },

      // 加载办理页面表单信息
      pageOpinion() {
        // 重置开始办理表单（写在这里方便记录未完成的意见）
        this.myOpinion = ""
        this.submitTo = ""
        this.submitToName = ""
        this.flowToLabel = ""

        // 根据部门名称,从字典查询配置好的流程
        this.getDictsByName(this.form.eunit).then(response => {
          this.flowToOptions = response.data
          if (this.flowToOptions.length == 0) {
            this.flowToOptions = this.defaultFlowToList
          }
        });

        // 根据wid获取流程信息，并设置默认流程节点+人
        const id = this.form.wid
        getFlow(id).then(response => {
          this.formOpt = response.data

          // 根据角色+部门获取人员列表
          const nextNodeK = this.formOpt.nextNodeK
          // 默认选择中流程
          this.submitTo = nextNodeK
          this.flowToLabel = this.formOpt.nextNode
          const userid = this.formOpt.userid
          selectOptions(userid, nextNodeK).then(response => {
            this.flowToNameOptions = response.data
            // 默认选择第一个
            if (this.flowToNameOptions.length>0) {
              this.submitToName = this.flowToNameOptions[0].userId
            }
          });

        });
      },

      // 开始办理
      handleOpinion() {
        if(this.form.nid==null){
          this.msgError("请先保存信息，再开始办理！");
          return;
        }

        if (this.fileList.length <= 0) {
          this.msgError("请至少上传一个文件！");
          return;
        }

        if(this.fileChange){// 附件发生变化
          console.log("附件发生变化...")
          this.msgError("上传附件后，请先保存！");
          return;
          //this.$refs.upload.submit();//调用requestUpload方法
        }

        this.openOpt = true;
      },

      /** 办理完成提交按钮 */
      submitOptForm() {
        // 遇到bug Textarea无法用validate，这个表单验证漏洞百出，屌用都没有，只能自己写
        if (this.myOpinion == null || this.myOpinion == '') {
          this.$message.error('办理人意见不能为空');
          return false
        } else {
          // 设置当前节点办理意见
          this.formOpt.opn = this.myOpinion;
        }
        if (this.submitTo == null || this.submitTo == '') {
          this.$message.error('请选择流程跳转至');
          return false
        } else {
          // 设置节点提交后的办理人角色名称+角色编码
          this.formOpt.currNodeK = this.submitTo
          this.formOpt.currNode = this.flowToLabel
        }
        if (this.flowToLabel != '流程结束' && (this.submitToName == null || this.submitToName == '')) {
          this.$message.error('办理人不能为空');
          return false
        } else {
          // 设置节点提交后办理人ID
          this.formOpt.userid = this.submitToName
        }
        // 补全参数(默认值)
        this.formOpt.flowToDeptid = null
        this.formOpt.flowToUserid = null
        this.formOpt.flowToRoleid = null
        this.formOpt.nextNode = null
        this.formOpt.nextNodeK = null

        // 根据下拉this.flowToOptions自动获取nextNode和nextNodeK
        var olen = this.flowToOptions.length
        const currNodeK = this.formOpt.currNodeK;
        if(currNodeK!='end'){
          for(var i=0;i<olen;i++){
            var obj = this.flowToOptions[i];//dictLabel   dictValue
            if(currNodeK==this.flowToOptions[i].dictValue){
              this.formOpt.nextNodeK = this.flowToOptions[i+1].dictValue
              this.formOpt.nextNode = this.flowToOptions[i+1].dictLabel
              break;
            }
          }
        }

        // 保存办理意见，流程跳转
        if (this.formOpt.nid != null) {
          saveFlow(this.formOpt).then(response => {
            console.log(response)
            var wid = response.wid;
            this.updateWstatus(wid)
          });
        }
      },
      
      //更新当前审批的W_STATUS和WID(0待办，1退回，2办理中，3流程结束)
      updateWstatus(wid) {
        this.form.wid = wid;
        var CurrNodeK = this.formOpt.currNodeK
        var status = this.getFlowStatus(CurrNodeK)
        this.form.wStatus = status
        if (this.form.nid != null) {
          updateNotice(this.form).then(response => {
            // console.log("5")
            this.msgSuccess("提交成功");
            this.open = false;
            this.openOpt = false
            this.getList();
          });
        }
      },

      /** 提交按钮 */
      submitForm() {
        /* if (this.fileList.length <= 0) {
          this.msgError("请至少上传一个文件！");
          return;
        } */

        this.$refs['form'].validate(valid => {
          if (valid) {
            if (this.form.nid != null) {/、修改、/
              console.log("updateNotice开始保存...")
              updateNotice(this.form).then(response => {
                // 上传附件
                const nid = response.nid;
                this.form.nid = nid;

                const wid = response.wid;
                this.form.wid = wid;
                if(this.fileChange){// 附件发生变化
                  console.log("附件发生变化...")
                  this.$refs.upload.submit();//调用requestUpload方法
                }else{
                  console.log("附件无变化...")
                  this.msgSuccess('保存成功')
                  // this.open = false
                  // this.getList()
                }

                //准备办理页面数据
                this.pageOpinion();

              })
            } else {/、新增、/
              if(this.form.keyword != null && this.form.keyword.length > 0) {
                var str = this.form.keyword;
                var reg = new RegExp( '，' , "g" )
                var newstr = str.replace( reg , ',' );
                this.form.keyword = newstr;
              }
              this.form.standardStatus = '1'
              //赋值起草人信息
              this.form.drafters = this.tableData;
              console.log("addNotice开始保存...")
              addNotice(this.form).then(response => {
                console.log(response)

                // 上传附件
                // const nid = response.nid;
                // this.form.nid = nid;
                // const wid = response.wid;
                // this.form.wid = wid;
                this.form = response.model;

                if(this.fileChange){// 附件发生变化
                  this.$refs.upload.submit();//调用requestUpload方法
                }else{
                  this.msgSuccess('保存成功')
                  // this.open = false
                  this.getList()
                }

                //准备办理页面数据
                this.pageOpinion();

              });
            }
          }
        })
      },

      /** 提交部门审核 */
      handleFlowTo() {
        if(this.form.nid==null){
          this.msgError("请先保存信息，再提交审核！");
          return;
        }

        if (this.fileList.length <= 0) {
          this.msgError("请至少上传一个文件！");
          return;
        }
        //2=办理中（部门审核），不设置时默认为0
        // this.form.wStatus = "2"
        this.$confirm('确认立项通知信息无误并提交部门负责人审核?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {

          // 先保存内容,再跳转流程
          this.submitForm();

          // 办理意见
          this.formOpt.opn = "请部门负责人审核";
          // 设置节点提交后的办理人角色名称+角色编码
          this.formOpt.currNodeK = "leader"
          this.formOpt.currNode = '部门负责人'
          // 部门负责人的userid（后台补齐）
          // 补全参数(默认值)
          this.formOpt.opt = '立项通知'
          this.formOpt.res = 'tb_nop_m'
          this.formOpt.userid = null
          this.formOpt.flowToDeptid = null
          this.formOpt.flowToUserid = null
          this.formOpt.flowToRoleid = null
          this.formOpt.nextNode = null
          this.formOpt.nextNodeK = null

          this.formOpt.nid = this.form.nid;
          saveFlow(this.formOpt).then(response => {
            console.log(response)
            var wid = response.wid;
            this.updateWstatus(wid)
          });
        })
      },

      /** 删除按钮操作 */
      handleDelete(row) {
        const nids = row.nid || this.ids
        this.$confirm('是否确认删除立项通知编号为"' + nids + '"的数据项?', '警告', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(function() {
          return delNotice(nids)
        }).then(() => {
          this.getList()
          this.msgSuccess('删除成功')
        })
      },
      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams
        this.$confirm('是否确认导出所有立项通知数据项?', '警告', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(function() {
          return exportM(queryParams)
        }).then(response => {
          this.download(response.msg)
        })
      },
      /** 下一步按钮操作 */
      next() {
        if (this.steps == 0 && this.form.stdTp == null) {
          this.$message.error('请选择标准规范种类');
          return false;
        }

        if (this.steps == 1 && this.form.stdUnit == null) {
          this.$message.error('请选择标准规范立项单位');
          return false;
        }

        if (this.form.stdUnit == '深圳市住房和建设局') {
          // 跳转住建局页面
          this.steps = 3;
        } else {
          if (this.steps++ > 3) this.steps = 0;
        }

      },
      back() {
        if (this.steps == 3) {
          this.steps = 1
        } else {
          if (this.steps-- < 0) this.steps = 0;
        }
      },
      skip() {
        if (this.steps++ > 3) this.steps = 3;
      },

      inputOpinion(value) {
        this.myOpinion += value.srcElement.innerText;
      },

      handleChangeMajor(value) {
        //console.log(value.length);
        var x = '';
        for (var i = 0; i < value.length; i++) {
          if (i == 0) {
            x = value[i];
          } else {
            x = x + "," + value[i];
          }
        }
        this.form.majorValue = x;
      },
      handleChangeFunction(value) {
        //console.log(value.length);
        var x = '';
        for (var i = 0; i < value.length; i++) {
          if (i == 0) {
            x = value[i];
          } else {
            x = x + "," + value[i];
          }
        }
        this.form.functionValue = x;
      },
      // 自我评价多选
      handleCheckedSelfEvla(value) {
        // console.log(value)
        var x = '';
        for (var i = 0; i < value.length; i++) {
          if (i == 0) {
            x = value[i];
          } else {
            x = x + "," + value[i];
          }
        }
        this.form.selfEvla = x;
      },

      //==================== 起草人信息 ====================
      handleAddDrafter() {
        // console.log(this.tableData)
        if(this.tableData.length==5){
          this.$message.error('最多填写5位起草人');
          return false;
        }
        this.resetDraftForm()
        this.openDraft = true
        // console.log(this.tableData)
      },

      handleDeleteDrafter(row){
        // this.tableData.splice(0,1);
        // var index = this.tableData.findIndex()
        // console.log(index)
        var did = row.did
        for(var i=0;i<this.tableData.length;i++){
          if(this.tableData[i].did==did){
            console.log("要删除的index是："+i)
            if(row.id!=null){
              const dids = [];
              dids.push(row.id)
              delDrafter(dids).then(response => {
                this.msgSuccess('删除起草人成功')
              });
            }
            this.tableData.splice(i,1);
          }
        }
      },

      handleUpdateDrafter(row){
        this.formDraft = row
        this.openDraft = true
      },

      submitDraftForm(){
        this.$refs['formDraft'].validate(valid => {
          if (valid) {

            const nid = this.form.nid;
            console.log(nid);
            const id = this.formDraft.id;
            const did = this.formDraft.did
            const dname = this.formDraft.dname;
            const dpost = this.formDraft.dpost;
            const dproject = this.formDraft.dproject;
            const dcompany = this.formDraft.dcompany;
            const dspeciality = this.formDraft.dspeciality;
            var item = {
              id: id,
              did: did,
              nid: nid,
              dname: dname,
              dpost: dpost,
              dproject: dproject,
              dcompany: dcompany,
              dspeciality: dspeciality
            };

            if (did != null) {
              for(var i=0;i<this.tableData.length;i++){
                if(this.tableData[i].did==did){
                  console.log("更新的index是："+i)
                  this.tableData[i] = item;

                  if(nid!=null&&id!=null) {
                    updateDrafter(item).then(response => {
                      this.msgSuccess('修改起草人成功')
                    });
                  }
                }
              }
            } else {
              item.did = this.tableData.length + 1;
              // console.log(item)
              // 必须要重新定义一个item，如果用push一个formDraft，tableData会被重新赋值影响
              if(nid!=null) {
                addDrafter(item).then(response => {
                  this.msgSuccess('添加起草人成功')
                  item.id = response.id;
                  console.log(item)
                });
              }
              this.tableData.push(item);
            }
            this.openDraft = false
          }
        })

      },

      resetDraftForm() {
        this.formDraft = {
          id: null,
          did: null,
          dname: null,
          dcompany: null,
          dpost: null,
          dspeciality: null,
          dproject: null
        };
        this.resetForm("formDraft");
      },

      //================= 附件方法 =================
      // 上传预处理
      beforeUpload(file) {
        console.log("beforeUpload...")
        const fileSuffix = file.name.substring(file.name.lastIndexOf(".") + 1);
        const whiteList = ["pdf", "doc", "docx"];
        if (whiteList.indexOf(fileSuffix) === -1) {
          this.msgError("上传文件只能是 pdf、doc、docx格式", "error");
          return false;
        }
        const isLt20M = (file.size / 1024 / 1024) < 20;
        if (!isLt20M) {
          this.msgError("上传文件大小不能超过 20MB", "error");
          return false;
        }
        console.log("- 文件大小格式符合通过...")
      },

      // 覆盖默认的上传行为（每个附件都会执行一次）
      requestUpload(value) {
        console.log("start upload...")
        let formData = new FormData();
        // 将附件循环赋值给后台参数uploadfileList[]
        this.uploadfileList[this.fileIndex++] = value.file

        if(this.countNewFile==this.uploadfileList.length){
          for(var i=0;i<this.uploadfileList.length;i++){
            formData.append("files", this.uploadfileList[i]);
          }
          formData.append("data", "");//项目信息
          formData.append("nid", this.form.nid);//项目ID
          updateUploadFile(formData).then(response => {
            // this.$refs.upload.clearFiles();
            this.msgSuccess("保存成功");

            const len = this.fileList.length
            if(len>0){//将文件状态改为success
              this.fileList[len-1].status = 'success'
            }
            // this.fileList = []
            this.uploadfileList = []
            this.fileChange = false
            this.fileIndex = 0
            this.countNewFile = 0
            // this.getList()
            // this.open = false
            console.log("- 附件上传成功！")
          });
        }
      },
      // 选中文件，list+1
      handleCheckFile(file, fileList) {
        console.log(file.size);
        this.fileList = fileList
        this.fileChange = true
        // 新增1个文件
        this.countNewFile++
      },
      // 查看附件
      handleViewFile(file, fileList){
        window.open(file.url)
      },
      // 删除附件
      handleRemoveFile(file, fileList){
        // 此处是被移除的file和fileList
        // 单独写一个移除方法,fileChange只有新上传了文件才改变
        this.fileChange = false
        // 判断是否已经上传到服务器的文件
        if(file.status=='success'){
          // 被移除附件名称
          console.log("删除文件："+file.url)
          let formData = new FormData();
          formData.append("fileName", file.url);//附件名称
          delUploadFile(formData).then(response => {
            console.log(response)
          });
        }else{
          this.countNewFile--
        }
      },
      beforeRemoveFile(file, fileList) {
        // if(this.optPage){
        //   this.msgError("办理中不能删除附件！");
        //   return false;
        // }
        if(this.optPage&&this.fileEditDisabled){//fileEditDisabled默认是false
          this.msgError("办理中不能删除附件！");
          return false;
        }
        return this.$confirm(`确定移除 ${ file.name }吗，移除后不能恢复？`);
      },
      // 文件上传中处理(添加requestUpload不起作用)
      handleFileUploadProgress(event, file, fileList) {
        console.log("handleFileUploadProgress...")
      },
      // 文件上传成功处理(添加requestUpload不起作用)
      handleFileSuccess(response, file, fileList) {
        console.log("handleFileSuccess")
        this.$refs.upload.clearFiles();
        this.$alert(response.msg, "提交结果", {
          dangerouslyUseHTMLString: true
        });
        //this.getList();
      },

    }
  }
</script>

<style>
  .bg-purple {
    background: #F8F8F9;
    height: 140px;
    text-align: center;
    padding-top: 15px;
    border: 1px solid #DFE6EB;
  }

  .span-title {
    color: #909399;
  }

  .radio-group-text span {
    font-size: 18px;
  }
</style>
